package cn.itcast.scala.course09

import cn.itcast.scala.course09.FileApp.file

import scala.io.Source

/**
  * Scala读取外部数据 -- 读取File中的内容
  * create by zhangtian on 2019/1/10
  */
object FileApp extends App {
  // val file = Source.fromFile("D:\\Developer\\IDEAWorkspace\\LearningScala2.11.12\\scala-train\\src\\main\\scala\\cn\\itcast\\scala\\course07\\flatMap",  "UTF-8")
  val file = Source.fromFile("D:\\Developer\\IDEAWorkspace\\LearningScala2.11.12\\scala-train\\src\\main\\scala\\cn\\itcast\\scala\\course07\\flatMap")(scala.io.Codec.UTF8)

  def readLine(): Unit = {
    for (fStr <- file.getLines()) {
      println(fStr)
    }
  }
 // readLine()  // 读完流就关闭了

  println("---------------------------------")
  def  readChar(): Unit ={
    for (ele <- file) {
      println(ele)
    }
  }
  // readChar()

  def readNet(): Unit ={ // 读取网络数据
    val file = Source.fromURL("https://www.baidu.com")(scala.io.Codec.UTF8)
    for (fStr <- file.getLines()) {
      println(fStr)
    }
  }

  readNet()
}
